/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.db.connection;

import java.sql.Connection;

import edu.uwm.universitydb.authenticaion.AuthenticationHelper;
import edu.uwm.universitydb.db.connection.mysql.MySQLDBConnection;
import edu.uwm.universitydb.framework.exception.DataAccessException;

/**
 * description of <code>DBConnectionFactory</type>
 * 
 * Singleton factory producing the DBConnection objects
 * 
 * @author Shyam Nair
 */
public class DBConnectionFactory
{
    /** static instance facilitating singleton */
    private static final DBConnectionFactory CONNECTION_FACTORY;
    
    // static block to initialize instance
    static
    {
        CONNECTION_FACTORY = new DBConnectionFactory();
    }

    /**
     * reducing the constructor visibility to avoid instantiation
     */
    private DBConnectionFactory()
    {
        // DO NOTHING
    }
    
    /**
     * <code>getDBConnection(...)</code> 
     * handle to obtain the instance of a DBConnection object
     * 
     * @return
     * @throws DataAccessException 
     */
    public Connection getDBConnection() throws DataAccessException
    {
        /*final String url =  "jdbc:mysql://localhost:3306/university";
        final String username = "root";
        final String password = "Welcome01";*/
    	
    	final String url =  AuthenticationHelper.getDbUrl();
        final String username = AuthenticationHelper.getUserName();
        final String password = AuthenticationHelper.getPassword();
        
        final MySQLDBConnection mySQLConnection = new MySQLDBConnection();
        return mySQLConnection.getConntection(url, username, password);
    }
    
    /**
     * <code>getInstance(...)</code> 
     * 
     * @return
     */
    public static DBConnectionFactory getInstance()
    {
        return CONNECTION_FACTORY;
    }
    
}


/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 6, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */